import Mock from 'mockjs';
import houseApi from './mockData/house.ts';
import request from "../utils/request";
import userApi from './mockData/user.ts';
import bookingApi from './mockData/booking';
import blacklistApi from './mockData/blacklist';

// 拦截请求
Mock.mock('/house/getData', houseApi.getHouseData());
export const getHouseData = () => request.get('/house/getData');

Mock.mock('/api/auth/userInfo', 'get', () => {
    return userApi.getUserInfo();
});
Mock.mock('/api/user/login', 'post', (options) => {
    const data = JSON.parse(options.body);
    return userApi.userLogin(data);
});
// 使用正则表达式匹配带参数的URL
Mock.mock(/\/api\/user\/list/, 'get', userApi.getUserList);
export const userLogin = (data: any) => request.post('/api/user/login', data);

// 新增预约相关Mock
Mock.mock('/api/booking/create', 'post', bookingApi.createBooking());
Mock.mock('/api/booking/my', 'get', bookingApi.getMyBookings());
Mock.mock(/\/api\/booking\/\d+/, 'put', bookingApi.updateBooking());
Mock.mock(/\/api\/booking\/\d+/, 'delete', bookingApi.cancelBooking());
Mock.mock(/\/api\/booking\/\d+\/transfer/, 'post', bookingApi.transferBooking());

// 黑名单相关
Mock.mock('/api/blacklist/list', 'get', blacklistApi.getList());
Mock.mock(/\/api\/blacklist\/\d+\/unban/, 'put', blacklistApi.unban());
Mock.mock(/\/api\/blacklist\/\d+$/,    'put', blacklistApi.extend());
// 添加删除用户的Mock配置
Mock.mock(/\/api\/user\/\d+/, 'delete', userApi.deleteUser);
// 添加更新用户的Mock配置
Mock.mock('/api/user', 'put', userApi.updateUser);
// 添加添加用户的Mock配置
Mock.mock('/api/user', 'post', userApi.insertUser);

Mock.mock(/\/api\//, (options) => {
    console.error(`[Mock] 未处理的API请求: ${options.url}`, options)
    return {
        status: false,
        code: 404,
        message: '未找到API路径，请检查Mock配置',
        data: null
    }
})